class Solution {
public:
    int lengthOfLastWord(const char *s) {
        // Start typing your C/C++ solution below
        // DO NOT write int main() function
    	if (s == NULL || *s == 0) {
			return 0;
		}
		int n = strlen(s);
		int i = n - 1;
		while (i >= 0 && s[i] == ' ') {
			--i;
		}
		if (i < 0) {
			return 0;
		}

		int ans = 0;
		while (i >= 0 && s[i] != ' ') {
			--i;
			++ans;
		}
		return ans;

    }
};